package com.newegg.bigmap.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.newegg.bigmap.service.DatabaseService;

@RestController
@RequestMapping()
public class API {
	
	@Autowired
	DatabaseService service;

    @RequestMapping(value="/{key}", method = RequestMethod.GET)
    public String get(@PathVariable String key) {
		return service.get(key);
    }
	
    @RequestMapping(value="/{key}", method = RequestMethod.POST)
    public long save(@PathVariable String key, @RequestBody String value) {
		return service.put(key, value);
    }
	
    @RequestMapping(value="/{key}", method = RequestMethod.DELETE)
    public String delete(@PathVariable String key) {
		return service.delete(key);
    }
	
    @RequestMapping(value="/", method = RequestMethod.GET)
    public long count() {
		return service.count();
    }
}
